const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("DZPToken", function () {
  let DZPToken;
  let token;
  let owner;
  let admin;
  let user;
  let feeReceiver;

  beforeEach(async function () {
    [owner, admin, user, feeReceiver] = await ethers.getSigners();
    DZPToken = await ethers.getContractFactory("DZPToken");
    token = await DZPToken.deploy(feeReceiver.address);
    await token.waitForDeployment();
  });

  it("should deploy the contract and mint initial supply", async function () {
    const balance = await token.balanceOf(owner.address);
    expect(await token.totalSupply()).to.equal(balance);
  });

  it("should allow owner to set fee receiver", async function () {
    await token.setFeeReceiver(feeReceiver.address);
    expect(await token.feeReceiver()).to.equal(feeReceiver.address);
  });

  it("should allow admin to add/remove from whitelist", async function () {
    await token.addAdmin(admin.address);
    await token.connect(admin).addToWhitelist(user.address);
    expect(await token.isWhitelisted(user.address)).to.equal(true);
    await token.connect(admin).removeFromWhitelist(user.address);
    expect(await token.isWhitelisted(user.address)).to.equal(false);
  });

  it("should transfer tokens with fee", async function () {
    const initialBalance = await token.balanceOf(user.address);
    const transferAmount = ethers.toBigInt("1000");
    await token.transfer(user.address, transferAmount);
    const finalBalance = await token.balanceOf(user.address);
    const feeBalance = await token.balanceOf(feeReceiver.address);
    expect(finalBalance - initialBalance + feeBalance).to.equal(transferAmount);
  });
});
